//
//  FileHandle.m
//  DoubanDemo1
//
//  Created by lanou3g on 15/11/28.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "FileHandle.h"
#import "UserInformation.h"
#import "DataBase.h"
@implementation FileHandle

static FileHandle *filHandle = nil;

+ (FileHandle *)shareInstance
{
    if (filHandle == nil) {
        filHandle = [[FileHandle alloc] init];
    
    }
    return filHandle;
}

#pragma mark ----用户信息-----

//同步
- (void)synchronize
{
    [[NSUserDefaults standardUserDefaults] synchronize];
}

//设置用户信息
- (void)setloginState:(BOOL)isLogin
{
    [[NSUserDefaults standardUserDefaults] setBool:isLogin forKey:@"isLogin"];
}
- (void)setUsername:(NSString *)username
{
    [[NSUserDefaults standardUserDefaults] setObject:username forKey:@"userName"];
}
- (void)setPassword:(NSString *)password
{
    [[NSUserDefaults standardUserDefaults] setObject:password forKey:@"password"];
    
}
- (void)setArrayMovie:(NSMutableArray *)arrayMovie
{
    NSData *data =  [DataBase dataOfArray:arrayMovie forKey:@"movieArr"];
//    NSLog(@"%@",data);
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"arrayMovie"];
}
- (void)setArrayActivity:(NSMutableArray *)arrayActivity
{
    NSData *data = [DataBase dataOfArray:arrayActivity forKey:@"activityArr"];
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"arrayActivity"];
}


//获取用户信息
- (BOOL)loginState
{
    return     [[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"];
    
}
- (NSString *)username
{
    return     [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
    
}
- (NSString *)password
{
    return     [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
    
}
- (NSMutableArray *)arrayMovie
{
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"arrayMovie"];
//    NSLog(@"%@",data);

    return [DataBase unarchiverObject:data forKey:@"movieArr"];
//    return [[NSUserDefaults standardUserDefaults] objectForKey:@"arrayMovie"];
}
- (NSMutableArray *)arrayActivity
{
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"arrayActivity"];
    return [DataBase unarchiverObject:data forKey:@"activityArr"];
}
- (UserInformation *)user
{
    UserInformation * user = [[UserInformation alloc] init];
    user.uesrName = [self username];
    user.password = [self password];
    user.movieAarry = (NSMutableArray *)[self arrayActivity];
    user.Activity = (NSMutableArray *)[self arrayActivity];
    user.isLogin = YES;
    
    return user;
}

@end
